<!--
 * @Description: 币种管理-编辑币种
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2024-03-05
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2025-02-14
-->
<script lang="ts" setup>
  import { Form, message } from 'ant-design-vue'
  import { computed, reactive, watch } from 'vue'

  import { HttpCodeEnum } from '/@/enums/httpEnum'

  const props = defineProps({
    visible: { type: Boolean, default: false },
    positionId: { type: Number, default: NaN },
    positionName: { type: String, default: '' },
  })

  const emits = defineEmits(['update:visible', 'success'])

  const visible = computed({
    get: () => props.visible,
    set: (val) => emits('update:visible', val),
  })

  watch(
    () => visible.value,
    (newVal) => {
      if (newVal) onPageShow()
      else onPageHide()
    },
  )

  /**
   * 页面显示
   */
  const onPageShow = () => initData()

  /**
   * 页面关闭
   */
  const onPageHide = () => resetFields()

  /**
   * 初始化数据
   */
  const initData = () => {
    form.state.name = props.positionName
  }

  /** 表单配置 */
  const form = reactive({
    state: {
      name: '',
    },
    rule: {
      name: [{ required: true, message: '请输入币种名称' }],
    },
    onOk: async () => {
      await validate()
      // const { responseCode } = await requestUpdatePosition({ positionId: props.positionId, positionName: form.state.name })
      // if (responseCode === HttpCodeEnum.SUCCESS) {
      //   message.success('修改成功')
      //   visible.value = false
      //   emits('success')
      // }
    },
  })
  /** 表单hook */
  const { validate, validateInfos, resetFields } = Form.useForm(form.state, form.rule)
</script>

<template>
  <div class="edit">
    <a-modal v-model:visible="visible" title="编辑岗位" @ok="form.onOk">
      <a-form-item label="币种名称" v-bind="validateInfos.name">
        <a-input v-model:value="form.state.name" />
      </a-form-item>
    </a-modal>
  </div>
</template>

<style lang="less" scoped></style>
